﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Swin_e_mon_Forms
{
    public class Location :GameEntity
    {
        public Location(string[] ids)
            : base(ids,true) 
        {}

        public Path LocatePath(string id)
        {
            foreach(Path p in paths)
                if( p.IdentifiedBy(id))
                    return p;
            return null;
        }

        public override string LongDescription
        {
            get
            {
                string[] splitDesc = Description.Split('%');
                string result = "";
                if (splitDesc.Length > 1)
                {
                    foreach (string s in splitDesc)
                        result += (s + "\n");
                    return result + "\n\nInside the " + Title + " you can see:\n\n" + Inventory.ItemList;
                }
                return base.LongDescription + "\n\nThere are the following paths from here:\n\n"+ PathList;
            }
        }

        public List<Path> paths = new List<Path>();

        public string PathList
        {
            get
            {
                string result = "";

                foreach (Path aPath in paths)
                    result += aPath.Title + "\n";
                return result;
            }
        }
    } 

    [TestFixture]
    public class TestLocation
    {
        [Test]
        public void ATestLocation()
        {
            Location aNewLoc = new Location(new string[] {"A Place"});
            Item bag = new Item(new string[] { "Bag" }, true);
            Item pen = new Item(new string[] { "Pen" }, false);

            pen.Title = "A pen title.";
            bag.Title = "A bag title.";
            aNewLoc.Title = "Badass Land";

            pen.Description = " pen desc";
            bag.Description = "bag desc";
            aNewLoc.Description = "This Location is Badass";

            bag.Inventory.AddItem(pen);
            aNewLoc.Inventory.AddItem(bag);

            Assert.AreSame(bag, aNewLoc.LocateEntity("bag"));
            Assert.IsNull(aNewLoc.LocateEntity("pen"));

        }
    
    
        [Test]
        public void TestPath()
        {
            Location aNewLoc = new Location(new string[] { "A Place" });
            aNewLoc.paths.Add(new Path(new string[] { "West" }, aNewLoc));
            aNewLoc.paths.Add(new Path(new string[] { "East" }, aNewLoc));

            Assert.AreSame(aNewLoc.paths[0],aNewLoc.LocatePath("west"));
            Assert.AreSame(aNewLoc.paths[1], aNewLoc.LocatePath("east"));
            Assert.IsNull(aNewLoc.LocatePath("null"));
        }

        public void TestPathList()
        {
            Location aNewLoc = new Location(new string[] { "A Place" });
            aNewLoc.paths.Add(new Path(new string[] { "West" }, aNewLoc));
            aNewLoc.paths.Add(new Path(new string[] { "East" }, aNewLoc));

            StringAssert.Contains(aNewLoc.PathList,"West");
            StringAssert.Contains(aNewLoc.PathList, "East");
            Assert.IsNull(aNewLoc.LocatePath("null"));
        }


    }
}
